package org.example.yasuo;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * reducer
 * KEYIN, reducer 阶段输入的key的类型：text
 * VALUEIN, reducer 阶段输入value类型 ：IntWritable
 * KEYOUT, reducer 阶段输出的key类型 text
 * VALUEOUT reducer 阶段输出的value类型 IntWritable
 */
public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

    private IntWritable outV = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {

        int num = 0;
        for (IntWritable value : values) {
            num += value.get();
        }
        outV.set(num);
        //写出
        context.write(key, outV);

    }
}
